/*
 * @Author: szx
 * @Date: 2022-01-04 13:44:54
 * @LastEditTime: 2022-01-04 13:53:26
 * @Description:
 * @FilePath: \leetcode\800-899\860\860.js
 */
/**
 * @param {number[]} bills
 * @return {boolean}
 */
var lemonadeChange = function (bills) {
    let five = 0,
        ten = 0;
    for (let i = 0; i < bills.length; i++) {
        if (bills[i] == 5) five++;
        else if (bills[i] == 10) {
            ten++;

            if (five > 0) five--;
            else return false;
        } else if (bills[i] == 20) {
            if (ten) {
                ten--;
                if (five) {
                    five--;
                } else return false;
            } else if (five >= 3) five -= 3;
            else return false;
        }
    }
    return true;
};
console.log(lemonadeChange([5, 5, 5, 10, 20]));
